package cn.kgc.springcloud.web.service.impl;

import cn.kgc.springcloud.web.client.ClazzClient;
import cn.kgc.springcloud.web.entity.Clazz;
import cn.kgc.springcloud.web.response.ResponseResult;
import cn.kgc.springcloud.web.vo.GroupVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.web.entity.Group;
import cn.kgc.springcloud.web.service.GroupService;
import cn.kgc.springcloud.web.mapper.GroupMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_group】的数据库操作Service实现
* @createDate 2024-07-29 10:04:19
*/
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService{

    @Resource
    private ClazzClient clazzClient;

    @Override
    public ResponseResult groupList() {

        List<Group> groups = baseMapper.selectList(null);

        List<GroupVO> collect = groups.stream().map(g -> {
            GroupVO groupVO = new GroupVO();
            BeanUtils.copyProperties(g,groupVO);

            Integer clazzid = g.getClazzid();
            Clazz oneClazz = clazzClient.getOneClazz(clazzid);
            groupVO.setClazz(oneClazz);

            return groupVO;
        }).collect(Collectors.toList());



        return ResponseResult.success().data(collect);
    }
}




